﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
using DevComponents.DotNetBar;

namespace QLST
{
    public partial class frmPhanNhom : Form
    {
        PhanNhomBUS cls = new PhanNhomBUS();
        PhanNhomDTO p = new PhanNhomDTO();

        public frmPhanNhom()
        {
            InitializeComponent();
        }

        private void frmPhanNhom_Load(object sender, EventArgs e)
        {
            ClearTextBox();
            LockTextBox(false);
            LockButton(true);
            LoadPN();
        }

        public void LoadPN()
        {
            gvPhanNhom.DataSource = cls.LoadPhanNhom();
        }

        
        //them
        private void btnThem_Click(object sender, EventArgs e)
        {
            LockButton(false);
            LockTextBox(true);
            ClearTextBox();
            gvPhanNhom.Enabled = false;
            cmb1.DataSource = cls.NV();
            cmb1.DisplayMember  = "MaNV";
            cmb1.ValueMember = "MaNV";
            cmb2.DataSource = cls.ND();
            cmb2.DisplayMember = "MaNhomNguoiDung";
            cmb2.ValueMember = "MaNhomNguoiDung";

        }
        //xoa
        private void btnXoa_Click(object sender, EventArgs e)
        {
            p.MaNV  = cmb1.Text ;

            cls.Xoa (p);
            frmPhanNhom_Load(sender, e);
        }
        //luu
        private void btnLuu_Click(object sender, EventArgs e)
        {
            p.MaNV = cmb1.Text;
            p.MaNhom = cmb2.Text;
            cls.Them (p);
            ClearGV();
            frmPhanNhom_Load(sender, e);
            gvPhanNhom.Enabled = true;
            MessageBoxEx.Show("Cập nhật thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //huy
        private void btnHuy_Click(object sender, EventArgs e)
        {
            ClearGV();
            frmPhanNhom_Load(sender, e);
            LockButton(true);
            LockTextBox(false);
            gvPhanNhom.Enabled = true;
        }

        private void gvPhanNhom_SelectionChanged(object sender, EventArgs e)
        {
            cmb1 .Text =gvPhanNhom .CurrentRow .Cells ["colMaNV"].Value .ToString ();
            cmb2 .Text =gvPhanNhom .CurrentRow .Cells ["colMaNND"].Value .ToString ();
        }

        private void ClearGV()
        {
            gvPhanNhom.ClearSelection();
        }

        private void ClearTextBox()
        {
            
        }

        private void LockButton(Boolean f)
        {
            btnThem.Enabled = f;
            btnXoa.Enabled = f;
            btnLuu.Enabled = !f;
            btnHuy.Enabled = !f;
        }

        private void LockTextBox(Boolean f)
        {
            cmb1.Enabled = f;
            cmb2.Enabled = f;
            if (f == false)
            {
               cmb1.BackColor = Color.LemonChiffon;
                cmb2.BackColor = Color.LemonChiffon;
               
            }
            else if (f == true)
            {
               cmb1.BackColor = Color.White;
                cmb2.BackColor = Color.White;
                
            }
        }
       
       
    }
}
